#ifndef DBSETUP_H
#define DBSETUP_H

#include <QString>
#include <QPair>
#include <QVector>
#include <QFile>
#include <QDebug>
#include <QSqlQuery>
#include <QStringList>
#include "DatabaseWork.h"

namespace DatabaseModule {

	typedef QPair<QString, QString> StringPair;
	typedef QVector<StringPair> PairVector;

	class DatabaseSetup {

	public:
		
		DatabaseSetup() 
			: forced(false), closeAfterAll(true), readyToSetup(false) {}
		DatabaseSetup(const QString& dbName) 
			: forced(false), closeAfterAll(true), readyToSetup(true), dbWorker(DatabaseWork(dbName)) {}
		DatabaseSetup(const DatabaseWork& worker)
			: forced(false), closeAfterAll(false), readyToSetup(true), dbWorker(worker) {}
		virtual ~DatabaseSetup() {}

		void setForcedMod(bool forced) {this->forced = forced;};
		bool getForcedMod() {return forced;};

		bool setup();

	private:

		bool forced;
		bool closeAfterAll;
		bool readyToSetup;
		DatabaseWork dbWorker;
		QStringList s;

		DatabaseSetup(const DatabaseSetup&);
		DatabaseSetup& operator=(const DatabaseSetup&);

		bool isFirstRun();
		bool fillDb();

		void finderStarter();
		QStringList getAllTables();
		PairVector pathFinder(const QString& current, const QString& parent, const QStringList& visited);
		QStringList findRelatedTables(const QString& tableName);
	};

}

#endif //DBSETUP_H